<%@ Import namespace="System" %>
<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Collections" %>
<%@ Import namespace="System.Collections.Generic" %>
<%@ Import namespace="System.Net" %>
<%@ Import namespace="System.IO" %>

<!--{{functions}}-->
<script language="c#" runat="server">

protected override void OnLoad(EventArgs e) {
	base.OnLoad(e);

    ReturnFileContent();
  //  ReturnCompressedContent();	
}

//for testing text output
protected void ReturnCompressedContent() {
	Response.Write("<font size=3 color=red><b>BLA-BLA-BLA-BLA</b></font>ssssddddddy");		
	Response.End();
}

//for testing binary files download,
protected void ReturnFileContent()
{
	Stream inputStream;
	using (inputStream = new FileStream(@Server.MapPath("img.jpg"), FileMode.Open))
	{
		int bytesRead;
		byte[] buf = new byte[64 * 1024];
		while ((bytesRead = inputStream.Read(buf, 0, buf.Length)) != 0)
		{
			Response.OutputStream.Write(buf, 0, bytesRead);
		}
	}
	
	string fileName = "img.jpg";
	string fileContentType = "image/jpeg";
	if (fileContentType != null)
	{
		Response.ContentType = fileContentType;
	}
	if (fileContentType == null || fileContentType == "application/octet-stream") {
		Response.AddHeader("Content-Disposition", 
			String.Format("attachment; filename={0};", fileName ));
	} else {
		Response.AddHeader("Content-Disposition", String.Format("filename={0}", fileName));
	}
		
//	Response.Flush();
//	Response.End(); 
}

</script>

